package leetcode.D1000.T986;

import java.util.ArrayList;
import java.util.List;

/**
 * @File Info: leetcode -- <Solution>
 * @Author: 18362
 * @Create: 2022-02-24 14:56:13 星期四
 */

class Solution {
    public int[][] intervalIntersection(int[][] firstList, int[][] secondList) {
        List<int[]> results = new ArrayList<>();
        int i = 0, j = 0;
        while (i < firstList.length && j < secondList.length) {
            int[] first = firstList[i], second = secondList[j];
            if (!(first[1] < second[0]) && !(first[0] > second[1]))
                results.add(new int[]{Math.max(first[0], second[0]), Math.min(first[1], second[1])});
            if (first[1] < second[1])
                ++i;
            else
                ++j;
        }
        return results.toArray(new int[results.size()][2]);
    }
}